package LeetCode.leetcode;

/**
 * 移除元素
 *
 * @author: leiwenkang02@meituan.com
 * @date: 2018/8/2
 * @time: 20:44
 */
public class Test27移除元素 {
    public static void main(String[] args) {
        int[] nums = {0,1,2,2,3,0,4,2};
        System.out.println(removeElement(nums, 2));
    }
    public static int removeElement(int[] nums, int val) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == val) {
                continue;
            } else {
                if (index != i) {
                    nums[index] = nums[i];
                }
                index++;
            }
        }
        return index;

    }
}
